package com.baofu.paycore.service.validate.impl.recharge;

import com.baofu.paycore.common.exception.ManagerErrorCode;
import com.baofu.paycore.common.exception.ValidateException;
import com.baofu.paycore.common.utils.Constant;
import com.baofu.paycore.service.facade.model.recharge.RechargeDTO;
import com.baofu.paycore.service.validate.AbstractPayValidate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * Description  :充值校验类
 * <p/>
 * Author       :LZQ
 * Date         :2014.12.04
 */
@Slf4j
@Service
public class RechargeValidate extends AbstractPayValidate<RechargeDTO> {

    /**
     * 充值参数校验
     *
     * @param rechargeDTO   充值参数
     */
    public void paramsValidate(RechargeDTO rechargeDTO){
        super.paramsValidate(rechargeDTO);
        if (rechargeDTO.getFundBaseDTO() == null){
            log.error("充值参数:{}", rechargeDTO);
            throw new ValidateException(ManagerErrorCode.PAYER_FUND_ORDER_NOT_EXIST);
        }
        Long fundAmt = Constant.validateLong(rechargeDTO.getFundBaseDTO().getAmt());
        if (!rechargeDTO.getAmt().equals(fundAmt)){
            log.error("支付充值主单总金额:{} 资金单充值金额:{} 资金单业务手续费金额:{}", rechargeDTO.getAmt(),
                    rechargeDTO.getFundBaseDTO().getAmt(), Constant.validateLong(
                            rechargeDTO.getFundBaseDTO().getBizChargeAmount()));
            throw new ValidateException(ManagerErrorCode.AMT_ERROR);
        }
        if (Constant.validateLong(rechargeDTO.getAmt()) <
                Constant.validateLong(rechargeDTO.getFundBaseDTO().getBizChargeAmount())){
            log.error("支付充值主单总金额:{} 资金单业务手续费金额:{}", rechargeDTO.getAmt(), Constant.validateLong(
                            rechargeDTO.getFundBaseDTO().getBizChargeAmount()));
            throw new ValidateException(ManagerErrorCode.FEE_AMT_NOT_MORE_PAY_AMT);
        }
    }
}
